package com.w.wx.controller;


import com.w.wx.domain.Msg;
import com.w.wx.service.impls.ImagesServiceImpl;


import com.w.wx.utils.ALToHMUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;



@RestController
@RequestMapping("/wx/images")
@Slf4j
public class ImagesContro {


    @Autowired
    private ImagesServiceImpl imagesService;

    /**
     * 上传物品图片接口
     * 参数flag为判断上传物品照片还是学生认证照片
     * flag==0为物品照片，flag==1为学生认证照片
     * @throws IOException
     */
    @PostMapping("/upload")
    public Msg uploadGoodsImages(HttpServletRequest request, MultipartFile file
            ,@RequestParam() String openid,Integer flag) throws IOException {
        return ALToHMUtil.retrunEasy(imagesService.setImageInfo(request,file,openid,flag));
    }

    /**
     * 获取首页轮播图
     */
    @RequestMapping("/getHomeImages")
    public Msg getHomeImages(){
        Msg msg = new Msg();
        msg.setMsg("获取成功");
        msg.setCode(200);
        msg.add("ershou1","http://8.131.63.146:10086/images/Aq4oR5ew2021324.jpg");
        msg.add("ershou2","http://8.131.63.146:10086/images/T8jmpQ0M2021324.jpg");
        msg.add("ershou3","http://8.131.63.146:10086/images/kC1Np0Je2021324.jpg");
        return msg;
    }

}
